def replaceEsp(fn):
    context = context_old = open(fn, 'r', errors='ignore').read()
    context = context.replace('ch9N', 'espN')
    context = context.replace('Ch9141', 'Esp')
    context = context.replace('ch9141', 'esp')
    context = context.replace('CH9141', 'ESP')
    if context_old != context:
        with open(fn, 'w') as f:
            f.write(context)


def replaceCh9(fn):
    context = context_old = open(fn, 'r', errors='ignore').read()
    context = context.replace('espN', 'ch9N')
    context = context.replace('Esp', 'Ch9141')
    context = context.replace('esp', 'ch9141')
    context = context.replace('ESP', 'CH9141')
    if context_old != context:
        with open(fn, 'w') as f:
            f.write(context)

def replaceNrf(fn):
    context = context_old = open(fn, 'r', errors='ignore').read()
    context = context.replace('espN', 'nrfN')
    context = context.replace('EspAtUart', 'Nrf24l01')
    context = context.replace('espAtUart', 'nrf24l01')
    context = context.replace('ESP_AT_UART', 'NRF24L01')
    if context_old != context:
        with open(fn, 'w') as f:
            f.write(context)

if __name__ == '__main__':
    replaceEsp('Drivers/scns/src/ScnsEspAtUart.c')
    replaceEsp('Drivers/scns/src/ScnsEspAtUart.h')
    replaceEsp('Drivers/scns/src/ScnsEspAtUart.c.h')

    replaceCh9('Drivers/scns/src/ScnsCh9141AtUart.c')
    replaceCh9('Drivers/scns/src/ScnsCh9141AtUart.h')
    replaceCh9('Drivers/scns/src/ScnsCh9141AtUart.c.h')

    replaceNrf('Drivers/scns/src/ScnsNrf24l01.c')
    replaceNrf('Drivers/scns/src/ScnsNrf24l01.h')
    replaceNrf('Drivers/scns/src/ScnsNrf24l01.c.h')